1. Field of Invention
The invention relates generally to computer systems. More particularly, methods and apparatus for automatically generating stubs in a multi-platform environment are disclosed.
2. Description of Relevant Art
The Java(trademark) programming language is an object-oriented high level programming language developed by Sun Microsystems and designed to be portable enough to be executed on a wide range of computers ranging from small personal computers up to supercomputers. Computer programs written in Java (and other languages) may be compiled into virtual machine instructions for execution by a Java virtual machine. In general the Java virtual machine is an interpreter that decodes and executes the virtual machine instructions.
The virtual machine instructions for the Java virtual machine are bytecodes, meaning they include one or more bytes. The bytecodes are stored in a particular file format called a xe2x80x9cclass filexe2x80x9d that includes bytecodes for methods of a class. In addition to the bytecodes for methods of a class, the class file includes a symbol table as well as other ancillary information.
A computer program embodied as Java bytecodes in one or more class files is platform independent. The computer program may be executed, unmodified, on any computer that is able to run an implementation of the Java virtual machine. The Java virtual machine is a software emulator of a xe2x80x9cgenericxe2x80x9d computer that is a major factor in allowing computer programs for the Java virtual machine to be platform independent.
The Java virtual machine is commonly implemented as a software interpreter. Conventional interpreters decode and execute the virtual machine instructions of an interpreted program one instruction at a time during execution. Compilers, on the other hand, decode source code into native machine instructions prior to execution so that decoding is not performed during execution. Because conventional interpreters decode each instruction before it is executed repeatedly each time the instruction is encountered, execution of interpreted programs is typically quite a bit slower than compiled programs because the native machine instructions of compiled programs can be executed on the native machine or computer system without necessitating decoding. Therefore, whenever performance is a significant factor, it is desirable to decode source code using the compiler instead of the interpreter. In order to accomplish this, however, what is referred to as an adapter translates the execution stack used by the platform dependent interpreter to a form that is consistent with what the platform dependent compiler expects. Unfortunately, since the code generated by the platform dependent compiler may store and communicate information in a manner different than the interpreter, a platform specific adapter must be constructed for each platform on which the virtual machine runs. This typically requires a user to generate an adapter using, for example, assembler language or C++ code, for each platform. Coding an adapter for each platform on which the virtual machine runs is quite time consuming and prone to error.
Typically, the Java virtual machine will be written in a programming language other than the Java programming language (e.g., the C++ programming language). Therefore, execution of a Java program may involve execution of functions written in multiple programming languages. Additionally, the bytecodes themselves may call native functions (e.g., system specific functions for input/output) that are not written in the Java programming language. It is therefore common for an executing Java program to entail the execution of functions that were written in multiple programming languages. A RPC (Remote Procedure Call) is a protocol that one program can use to request a service from a program located in another computer in a network without having to understand network details. A procedure call is also sometimes known as a function call or a subroutine call. Using a client server model, the requesting program is a client and the service-providing program is the server. As in a regular or local procedure call, an RPC is a synchronous operation requiring the requesting program to be suspended until the results of the remote procedure are returned. However, the use of lightweight processes or threads that share the same address space allows multiple RPCs to be performed concurrently.
When program statements that use RPC are compiled into an executable program, a stub is included in the compiled code that acts as the representative of the remote procedure code. A stub is a small program routine that substitutes for a longer program, possibly to be loaded later or that is located remotely. For example, a program that uses Remote Procedure Calls (RPCs) is compiled with stubs that substitute for the program that provides a requested procedure. The stub accepts the request and then forwards it (through another program) to the remote procedure. When that procedure has completed its service, it returns the results or other status to the stub that passes it back to the program that made the request.
As with the adapter, in conventional virtual machines, a manually coded stub library is required for every platform on which the virtual machine runs. Coding a stub for every RPC for each platform on which the virtual machine runs is quite time consuming and prone to error.
Accordingly, there is a need for techniques for automatically generating a library of platform dependent adapters. Additionally, there is a need to provide techniques for automatically providing a library of platform dependent stubs for each platform on which the virtual machine runs.
In general, embodiments of the present invention provide innovative systems and methods for automatically generating a library of platform dependent adapters and stubs for use in a virtual machine.
An apparatus for executing a bytecode in runtime system and automatically providing an adapter or a stub is disclosed. The apparatus includes a bytecode source coupled to an interpreter unit. The interpreter being used to interpret the bytecode. The interpreter is in turn coupled to the runtime system which executes the interpreted bytecode. The bytecode source is also coupled to a compiler that is used to compile the bytecode. The compiler, in turn, is coupled to the runtime system that executes the compiled bytecode. The apparatus also includes an adapter/stub generator unit coupled to the compiler that provides on demand an adapter or a stub to the runtime system as needed.
In a preferred embodiment, a library coupled to the runtime system is used to store adapters and stubs which are then retrieved as needed by the runtime system.
In another embodiment, a computer program product that implements an apparatus for processing a bytecode in a runtime system is disclosed. The program product includes computer code that interprets a received bytecode and passes the interpreted bytecode to the runtime system to be executed. The computer code also compiles the received bytecode and passes the compiled bytecode to the runtime system for execution. The computer code also generates an adapter when requested by the runtime system in order to execute the bytecode.
In another embodiment, a computer implemented method for processing a bytecode in a runtime environment is disclosed. If an adapter is required in order to process the bytecode a determination is made whether or not the required adapter is in an adapter library. If the required adapter is not in the adapter library, the an adapter generator builds the adapter and stores it in the library which then provides the adapter to the runtime system which then executes the bytecode.
Other features and advantages of the invention will become readily apparent upon review of the following detailed description in association with the accompanying drawings.